package com.naishuo.bigevent.controller.user;


import com.naishuo.bigevent.pojo.Article;
import com.naishuo.bigevent.pojo.PageBean;
import com.naishuo.bigevent.pojo.Result;
import com.naishuo.bigevent.service.ArticleService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleConteoller {
    @Autowired
    private ArticleService articleService;

    @PostMapping()
    public Result addarticle(@RequestBody @Validated Article article){

        System.out.println(article);
        articleService.addarticle(article);

        return Result.success();

    }

    @GetMapping()
    public Result<PageBean<Article>> list(Integer pageNum,Integer pageSize,
                                          @RequestParam(required = false)Integer categoryId,
                                          @RequestParam(required = false)String state){
        return Result.success(articleService.list(pageNum,pageSize,categoryId,state));
    }

    @GetMapping("/detail")
    public List<Article> findAllById(Integer id){
        return articleService.findAllById(id);
    }

    @PutMapping()
    public Result updateArticle(@RequestBody Article article){
        System.out.println(article);
        articleService.updatearticle(article);
        return Result.success();
    }


    @DeleteMapping()
    public Result deleteArticle(Integer id){
        articleService.deleteArticle(id);
        return Result.success();
    }





}
